<!--
 * @Author: huang liang miao 1127255342@qq.com
 * @Date: 2024-11-21 16:15:46
 * @LastEditors: huang liang miao 1127255342@qq.com
 * @LastEditTime: 2025-01-16 11:00:39
 * @FilePath: \sr_system_manager_ui\src\views\home\components\ModuleList.vue
 * @Description: 首页/工作台-常用功能
-->
<script setup lang="ts">
import useUserStore from '@/store/modules/user'
import { getPointCountPage } from "@/api/home/index"

const userStore = useUserStore()
const achvList = ref() // 成果
const horizontalList = ref() // 横向
const schoolLevelList = ref() // 校级
const verticalList = ref() // 纵向
const identity = computed(() => {
	return userStore.currentIdentityCode === 'NORMAL' ? 'mine' : userStore.currentIdentityCode === 'FACULTY_ADMIN' ? 'college' : 'office'
})

const type1 = [2,5,7,24,25,13] // 纵向、校级项目列表
const type2 = [7] // 中检管理
const type3 = [13] // 变更管理
const type4 = [24,25] // 结项管理
const type5 = [16,,19,10,24,25] // 横向项目列表

const itemList = ref<any>([
  // 教职工
  {
    userType: ['NORMAL'],
    title: '我的项目',
    children: [
      {
        path: '/project/mine/create?projectNature=1',
        class: 'item-type-2',
        otherClass: 'item-other',
        icon: 'icon-xincengzongxiangweixiang',
        name: '新建纵向',
        name2: '项目'
      },
      {
        path: '/project/mine/create?projectNature=3',
        class: 'item-type-1',
        otherClass: 'item-other',
        icon: 'icon-xincenghuangxiangxiangmu',
        name: '新建横向',
        name2: '项目'
      },
      {
        path: '/project/mine/create?projectNature=2',
        class: 'item-type-6',
        otherClass: 'item-other',
        icon: 'icon-xincengjiaojixiangmu',
        name: '新建校级',
        name2: '项目'
      }
    ]
  },
  // 管理员
  {
    userType: ['MANAGER_SCHOOL_ADMIN', 'SCIENTIFIC_RESEARCH_ADMIN'],
    title: '纵向项目',
    children: [
      {
        path: '/project/portrait/portraitManage?projectNature=1',
        class: 'item-type-1',
        icon: 'icon-xiangmulibiao',
        type: type1,
        count: null,
        name: '项目列表'
      },
      {
        path: '/project/portrait/portraitIntermediateInspection?projectNature=1',
        class: 'item-type-2',
        icon: 'icon-zhongjianguanli',
        type: type2,
        count: null,
        name: '中检管理'
      },
      {
        path: '/project/portrait/portraitChange?projectNature=1',
        class: 'item-type-3',
        icon: 'icon-biangengguanli',
        type: type3,
        count: null,
        name: '变更管理'
      },
      {
        path: '/project/portrait/portaitConclusion?projectNature=1',
        class: 'item-type-4',
        icon: 'icon-xiangmujiexiang',
        type: type4,
        count: null,
        name: '结项管理'
      }
    ]
  },
  // 管理员
  {
    userType: ['MANAGER_SCHOOL_ADMIN', 'SCIENTIFIC_RESEARCH_ADMIN'],
    title: '横向项目',
    children: [
      {
        path: '/project/portrait/portraitManage?projectNature=3',
        class: 'item-type-1',
        icon: 'icon-xiangmulibiao',
        type: type5,
        count: null,
        name: '项目列表'
      },
      {
        path: '/project/portrait/portraitChange?projectNature=3',
        class: 'item-type-3',
        icon: 'icon-biangengguanli',
        type: type3,
        count: null,
        name: '变更管理'
      },
      {
        path: '/project/portrait/portaitConclusion?projectNature=3',
        class: 'item-type-4',
        icon: 'icon-xiangmujiexiang',
        type: type4,
        count: null,
        name: '结项管理'
      }
    ]
  },
  // 管理员
  {
    userType: ['MANAGER_SCHOOL_ADMIN', 'SCIENTIFIC_RESEARCH_ADMIN'],
    title: '校级项目',
    children: [
      {
        path: '/project/portrait/portraitManage?projectNature=2',
        class: 'item-type-1',
        icon: 'icon-xiangmulibiao',
        type: type1,
        count: null,
        name: '项目列表'
      },
      {
        path: '/project/portrait/portraitIntermediateInspection?projectNature=2',
        class: 'item-type-2',
        icon: 'icon-zhongjianguanli',
        type: type2,
        count: null,
        name: '中检管理'
      },
      {
        path: '/project/portrait/portraitChange?projectNature=2',
        class: 'item-type-3',
        icon: 'icon-biangengguanli',
        type: type3,
        count: null,
        name: '变更管理'
      },
      {
        path: '/project/portrait/portaitConclusion?projectNature=2',
        class: 'item-type-4',
        icon: 'icon-xiangmujiexiang',
        type: type4,
        count: null,
        name: '结项管理'
      }
    ]
  },
  // 除了标题，其他不区分人员身份
  {
    userType: ['NORMAL', 'FACULTY_ADMIN', 'MANAGER_SCHOOL_ADMIN', 'SCIENTIFIC_RESEARCH_ADMIN'],
    title: userStore.currentIdentityCode === 'NORMAL' ? '我的成果' : '成果管理',
    children: [
      {
        path: `/achievementReward/${identity.value}/${identity.value}-academic-paper`,
        class: 'item-type-1',
        icon: 'icon-Property2wenjian',
        achvType: 0,
        count: null,
        name: '学术论文'
      },
      {
        path: `/achievementReward/${identity.value}/${identity.value}-academic-work`,
        class: 'item-type-3',
        icon: 'icon-xueshuzhuzuo',
        achvType: 1,
        count: null,
        name: '学术著作'
      },
      {
        path: `/achievementReward/${identity.value}/${identity.value}-patent`,
        class: 'item-type-2',
        icon: 'icon-ruanzhu',
        achvType: 2,
        count: null,
        name: '专利/软著'
      },
      {
        path: `/achievementReward/${identity.value}/${identity.value}-vertical`,
        class: 'item-type-5',
        icon: 'icon-zongxiangweixiang',
        achvType: 3,
        count: null,
        name: '纵向项目'
      },
      {
        path: `/achievementReward/${identity.value}/${identity.value}-horizontal`,
        class: 'item-type-2',
        icon: 'icon-huangxiangxiangmu',
        achvType: 4,
        count: null,
        name: '横向项目'
      },
      {
        path: `/achievementReward/${identity.value}/${identity.value}-guide-student`,
        class: 'item-type-5',
        icon: 'icon-zhidaoxuesheng',
        achvType: 5,
        count: null,
        name: '指导学生科研',
        name2: '项目结项'
      },
      {
        path: `/achievementReward/${identity.value}/${identity.value}-laboratory`,
        class: 'item-type-6',
        icon: 'icon-shiyanshi',
        achvType: 6,
        count: null,
        name: '重点实验室/科研',
        name2: '团队立项/结项'
      },
      {
        path: `/achievementReward/${identity.value}/${identity.value}-research-award`,
        class: 'item-type-3',
        icon: 'icon-Property1jiangbei',
        height: true,
        achvType: 7,
        count: null,
        name: '科研获奖'
      },
      {
        path: `/achievementReward/${identity.value}/${identity.value}-sports-competition`,
        class: 'item-type-1',
        icon: 'icon-benyanjingsai',
        height: true,
        achvType: 8,
        count: null,
        name: '体育竞赛'
      },
      {
        path: `/achievementReward/${identity.value}/${identity.value}-other`,
        class: 'item-type-4',
        icon: 'icon-qiyichengluo',
        height: true,
        achvType: 9,
        count: null,
        name: '其他成果'
      }
    ]
  },
  // 管理人员
  {
    userType: ['MANAGER_SCHOOL_ADMIN', 'SCIENTIFIC_RESEARCH_ADMIN'],
    title: '考核奖励',
    children: [
      {
        path: '/achievementReward/assessmentReward/researchAssessment',
        class: 'item-type-3',
        icon: 'icon-Property1shenhe',
        name: '科研考核'
      },
      {
        path: '/achievementReward/assessmentReward/managerWay',
        class: 'item-type-2',
        icon: 'icon-kexingkaohe',
        name: '管理办法'
      },
      {
        path: '/achievementReward/assessmentReward/researchReward',
        class: 'item-type-4',
        icon: 'icon-kexingjiangli',
        name: '科研奖励'
      },
      {
        path: '/achievementReward/assessmentReward/rewardWay',
        class: 'item-type-1',
        icon: 'icon-kaohebanfa',
        name: '奖励办法'
      },
      {
        path: '/achievementReward/researchStat',
        class: 'item-type-6',
        icon: 'icon-Property1bingtu',
        name: '科研统计'
      }
    ]
  },
  // 教职工
  {
    userType: ['NORMAL'],
    title: '考核与奖励',
    children: [
      {
        path: '/achievementReward/myResearchPoint',
        class: 'item-type-3',
        icon: 'icon-gerenjifen',
        height: true,
        name: '我的科研分',
      },
      {
        path: '/achievementReward/personalRewardPoint',
        class: 'item-type-1',
        otherClass: 'item-other',
        icon: 'icon-xincengyouxiuwenhuachengluo',
        name: '我的奖励',
        name2: '积分'
      },
    ]
  },
  // 超级管理员
  {
    userType: ['MANAGER_SUPER_ADMIN'],
    title: '系统管理',
    children: [
      {
        path: '/system/user',
        class: 'item-type-1',
        icon: 'icon-yonghu',
        name: '用户管理',
      },
      {
        path: '/system/role',
        class: 'item-type-2',
        icon: 'icon-jiaose',
        name: '角色管理',
      },
      {
        path: '/system/userlog',
        class: 'item-type-3',
        icon: 'icon-yonghurizhi',
        name: '用户日志',
      },
      {
        path: '/system/operlog',
        class: 'item-type-5',
        icon: 'icon-caozuorizhi',
        name: '操作日志',
      },
      {
        path: '/system/dict',
        class: 'item-type-6',
        icon: 'icon-zidian',
        name: '字典管理',
      },
      {
        path: '/system/menu',
        class: 'item-type-4',
        icon: 'icon-caishan',
        name: '菜单管理',
      }
    ]
  },
])

// 查询常用功能数量
const { run: getPointCount } = useRequest(getPointCountPage, {
  // false 为自动执行
  manual: true,
  // 请求成功
  onSuccess: (data: any) => {
    verticalList.value = data.verticalVOList || []
    horizontalList.value = data.horizontalVOList || []
    schoolLevelList.value = data.schoolLevelVOList || []
    achvList.value = data.achvVOList || []
    // 纵向
    itemList.value[1].children.forEach((item: any) => {
      verticalList.value.filter(n => item.type?.includes(n.projectStatus))?.map(v => {
        item.count += v.approveCount
      })
    });
    // 横向
    itemList.value[2].children.forEach((item: any) => {
      horizontalList.value.filter(n => item.type?.includes(n.projectStatus))?.map(v => {
        item.count += v.approveCount
      })
    });
    // 校级
    itemList.value[3].children.forEach((item: any) => {
      schoolLevelList.value.filter(n => item.type?.includes(n.projectStatus))?.map(v => {
        item.count += v.approveCount
      })
    });
    // 成果
    itemList.value[4].children.forEach((item: any) => {
      item.count = achvList.value.filter(n => n.achvType === item.achvType)[0]?.approveCount
    });
  },
})
onMounted(() => {
  if(!['NORMAL', 'MANAGER_SUPER_ADMIN'].includes(userStore.currentIdentityCode)){
    getPointCount()
  }
})

</script>

<template>
  <el-scrollbar height="100%">
    <template v-for="item in itemList" :key="item.title">
      <div v-if="item.userType.includes(userStore.currentIdentityCode)" class="module-items">
        <div class="module-title">{{item.title}}</div>
        <div class="module-list">
          <div v-for="v in item.children" :key="v.name" :class="`module-item ${v.class}`">
            <el-badge :value="v.count || 0" :max="99" :offset="[10, -10]" :show-zero="false" color="#F53F3F" class="w-full!">
              <router-link :to="v.path" class="flex items-center">
                <div :class="`icon-module ${v.class}`">
                  <i :class="`iconfont ${v.icon} text-[16px]`" />
                </div>
                <div :class="{'text-[12px] leading-[12px]' : v.name2, 'item-other' : v.otherClass}" class="module-nane">
                  <div>{{v.name}}</div>
                  <div v-if="v.name2" class="mt-[4px]">{{v.name2}}</div>
                </div>
              </router-link>
            </el-badge>
          </div>
        </div>
      </div>
    </template>
  </el-scrollbar>
</template>

<style lang="scss" scoped>
  .el-scrollbar{
    @apply: pr-[20px];
    height: calc(100% - 38px);
  }
  .module-items{
    @apply: text-[#1D2129] font-700 pt-[16px];
  }
  .module-list{
    @apply: mb-[24px];
    .module-item{
      @apply: inline-block w-[160px] py-[12px] px-[16px] mt-[20px] mr-[20px] text-[14px] text-[#4E5969] cursor-pointer rounded-[8px];
      vertical-align: top;
      .module-nane{
        @apply: ml-[12px];
      }
      .icon-module{
        @apply: w-[28px] h-[28px] leading-[28px] text-center text-white rounded-full font-normal;
      }
      .item-type-1{
        background: linear-gradient(131deg, #6DA5FF 15.21%, #3D7AFF 85.83%);
      }
      .item-type-2{
        background: linear-gradient(131deg, #13D9D1 15.21%, #0EB2D5 85.83%);
      }
      .item-type-3{
        background: linear-gradient(131deg, #FFB15F 15.21%, #FF972A 85.83%);
      }
      .item-type-4{
        background: linear-gradient(131deg, #FF8A83 15.21%, #FF6F59 85.83%);
      }
      .item-type-5{
        background: linear-gradient(131deg, #6ED470 15.21%, #31B865 85.83%);
      }
      .item-type-6{
        background: linear-gradient(131deg, #B083FE 15.21%, #775FFB 85.83%);
      }
      .item-other{
        @apply: text-[12px] h-[28px];
      }
    }
    
    & .item-type-1{
      @apply: bg-[#F0F5FF];
      &:hover{
        @apply: bg-[#E6EFFF];
      }
    }
    & .item-type-2{
      @apply: bg-[#EBFAFA];
      &:hover{
        @apply: bg-[#E1FAFA];
      }
    }
    & .item-type-3{
      @apply: bg-[#FFF8F0];
      &:hover{
        @apply: bg-[#FFF3E6];
      }
    }
    & .item-type-4{
      @apply: bg-[#FFF1F0];
      &:hover{
        @apply: bg-[#FFE7E6];
      }
    }
    & .item-type-5{
      @apply: bg-[#EDFDEF];
      &:hover{
        @apply: bg-[#E4FDE7];
      }
    }
    & .item-type-6{
      @apply: bg-[#F6F2FF];
      &:hover{
        @apply: bg-[#F0E8FF];
      }
    }
  }
  .super-item{
    .module-item{
      @apply: mr-[20px];
      &:nth-child(5n){
        @apply: mr-[20px];
      }
    }
  }
</style>